﻿//console.log('注入,发消息');
var _url = window.location.href;
if (_url.indexOf("/a999_Personal/main_20170721.aspx") > -1 || _url.indexOf("a999_Personal/main_20220210.aspx") > -1 || _url.indexOf("a999_Personal/main_20220209.aspx") > -1) {
    document.getElementById("right").addEventListener("load", function () {
        var url = document.getElementById("right").src;
        chrome.runtime.sendMessage({ url: url, title: document.title }, function (response) { });
    });
}
else {
    chrome.runtime.sendMessage({ url: window.location.href, title: document.title }, (response) => {
        //console.log('收到来自后台的回复：' + response);
    });
}

window.addEventListener('hashchange', () => {
    //url变化监听
    //console.log("ok");
})

/*
// 监听长连接
chrome.runtime.onConnect.addListener(function (port) {
    console.log(port);
    if (port.name == 'test-connect') {
        port.onMessage.addListener(function (msg) {
            console.log('收到长连接消息：', msg);
            if (msg.question == '你是谁啊？') port.postMessage({ answer: '我是你爸！' });
        });
    }
});
*/
 

// 后台监听事件消息
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    console.log(message, sender, sendResponse);
});
